<template>
	<view class="setting-container">
		<!-- 设置列表 -->
		<view class="setting-list">
			<view class="setting-item" @click="navigateTo('/pages/parse/parse?title=用户协议&code=service_agreement')">
				<view class="item-left">用户协议</view>
				<view class="item-right">
					<uni-icons type="right" color="#000" size="25" />
				</view>
			</view>
			
			<view class="setting-item" @click="navigateTo('/pages/parse/parse?title=隐私政策&code=privacy_policy')">
				<view class="item-left">隐私政策</view>
				<view class="item-right">
					<uni-icons type="right" color="#000" size="25" />
				</view>
			</view>
			
			<view class="setting-item">
				<view class="item-left">关于我们</view>
				<view class="item-right">
					<uni-icons type="right" color="#000" size="25" />
				</view>
			</view>
			
			<view class="setting-item" @click="clearCache">
				<view class="item-left">清除缓存</view>
				<view class="item-right">
					<uni-icons type="right" color="#000" size="25" />
				</view>
			</view>
			
			<view class="setting-item" @click="showToses">
				<view class="item-left">注销账号</view>
				<view class="item-right">
					<uni-icons type="right" color="#000" size="25" />
				</view>
			</view>
		</view>
		
		<!-- 退出登录按钮 -->
		<view class="logout-btn" @click="showLogoutConfirm">退出登录</view>
	</view>
</template>

<script>
/**
 * 设置页面
 * @description 用户设置和账号管理页面
 */
export default {
	data() {
		return {
			/**
			 * 缓存大小
			 * @type {String}
			 */
			cacheSize: '0MB'
		};
	},
	onLoad() {
		// 获取缓存大小
		this.getCacheSize();
	},
	methods: {
		/**
		 * 获取缓存大小
		 */
		getCacheSize() {
			// 模拟获取缓存大小，实际应用中可能需要调用原生API
			this.cacheSize = '12.5MB';
		},
		
		/**
		 * 导航到指定页面
		 * @param {String} url - 页面路径
		 */
		navigateTo(url) {
			uni.navigateTo({
				url: url
			});
		},
		
		/**
		 * 清除缓存
		 */
		clearCache() {
			uni.showModal({
				title: '提示',
				content: '确定要清除缓存吗？',
				success: (res) => {
					if (res.confirm) {
						// 显示加载中
						uni.showLoading({
							title: '清除中...'
						});
						
						// 模拟清除缓存
						setTimeout(() => {
							uni.hideLoading();
							this.cacheSize = '0MB';
							uni.showToast({
								title: '清除成功',
								icon: 'success'
							});
						}, 1000);
					}
				}
			});
		},
		showToses(){
			uni.showToast({
				title: '暂未开放',
				icon: 'none'
			});
		},
		/**
		 * 显示退出登录确认框
		 */
		showLogoutConfirm() {
			uni.showModal({
				title: '提示',
				content: '确定要退出登录吗？',
				success: (res) => {
					if (res.confirm) {
						this.logout();
					}
				}
			});
		},
		
		/**
		 * 退出登录
		 */
		logout() {
			// 清除登录状态
		    this.$api('/app/logout').then(res=>{
				this.$store.dispatch('logout')
				// 跳转到登录页
				uni.reLaunch({
					url: '/pages/login/login'
				});
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.setting-container {
	min-height: 100vh;
	background-color: #fff;
	// 设置列表
	.setting-list {
		background-color: #ffffff;
		
		.setting-item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 30rpx;
			border-bottom: 1rpx solid #f0f0f0;
			
			.item-left {
				font-size: 30rpx;
				color: #333333;
			}
			
			.item-right {
				display: flex;
				align-items: center;
				
				.arrow-icon {
					width: 40rpx;
					height: 40rpx;
				}
			}
		}
	}
	
	// 退出登录按钮
	.logout-btn {
		margin: 60rpx 30rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		background-color: #529AEE;
		color: #fff;
		font-size: 32rpx;
		font-weight: bold;
		border-radius: 45rpx;
	}
}
</style>
